#!/usr/bin/python
#!coding=utf-8
#filename:writedb.py

import sqlite3
import re

def parsetxt(fc):
    mdata_temp = []
    mdata = []
    
    mdata_temp =  fc.split('|||')
    for i in range(len(mdata_temp)):
        mdata.append([])
        for j in range(5):            
            mdata[i] = mdata_temp[i].split('||')
    return mdata


    
if __name__ == '__main__':
    file = r'mdata.txt'
    f = open(file)
    fc = f.read()
    
    mdata = parsetxt(fc)
    conn = sqlite3.connect('movie.db')
    cur = conn.cursor()
    
    for i in range(len(mdata)-1):
        cur.execute('insert into movie(mname, mdate, detail1, detail2) values(?, ?, ?, ?)', (mdata[i][0], mdata[i][1], mdata[i][2], mdata[i][3]))
    f.close()
    conn.commit()
    cur.close()
    conn.close()
